-
Notifications
You must be signed in to change notification settings - Fork 25
chore: Improve type hints for async bound_params
, auth_token_getters
, and client_headers
#249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
bound_params
and auth_token_getters
bound_params
and auth_token_getters
bound_params
, auth_token_getters
, and client_headers
Why are we using callables that take no args? I believe |
We expect the user to pass in functions that produce values without depending on anything from inside the tool or client. Does that make sense? |
I was wondering why not allow users to bind params based on anything from tool or client or even just env variables. |
Could you provide some use cases if possible? Thinking about this a bit more, I see one use case where users might want to pass in tool's name, for instance, as one of the bound param values. Just thinking if something like that might sound like a future PR? |
This PR enhances the type hints for
bound_params
,auth_token_getters
, andclient_headers
arguments in the APIs of both tool and client classes.Previously, these type hints incorrectly suggested that these callables could only be synchronous functions, or in some cases, specifically
Coroutine
objects:auth_token_getters
: ExpectedCallable[[], str]
bound_params
: ExpectedCallable[[], Any]
client_headers
:Coroutine
This was inaccurate as these can also be asynchronous (
async def
) functions.This PR corrects the type hints to accurately reflect that these callables can be either synchronous or asynchronous:
auth_token_getter
: Now acceptsCallable[[], str]
orCallable[[], Awaitable[str]]
.bound_params
: Now acceptsCallable[[], Any]
orCallable[[], Awaitable[Any]]
.client_headers
: Now acceptsCallable[[], Any]
orCallable[[], Awaitable[str]]
.This ensures type checkers correctly validate both synchronous and asynchronous implementations for these parameters.
This PR also improves accuracy for
auth_token_getter
signatures to be more abstract parameter types:* Previously: For
auth_token_getter
callables that accepteddict
arguments in their own signature.* Now: These have been updated to use
typing.Mapping
. This is more accurate as it allows for any object implementing the mapping protocol (not justdict
instances), offering greater flexibility.